/**
 * Project Name:SimonFramework
 * File Name:DiskCacheUtils.java
 * Package Name:com.simon.framework.image.utils
 * Date:2016-5-19 下午1:58:17
 * Copyright (c) 2016, simon@cmonbaby.com All Rights Reserved.
 */
package com.cmonbaby.images.utils;

import com.cmonbaby.images.cache.disc.DiskCache;

import java.io.File;

/**
 * <p>Author:      Simon
 * <p>QO:          8950764
 * <p>Email:       simon@cmonbaby.com
 * <p>WebSize:     https://www.cmonbaby.com
 * <p>Version:     1.0.0
 * <p>Date:        2020/12/29
 * <p>Description: 磁盘缓存工具
 */
public class DiskCacheUtils {

    private DiskCacheUtils() {
    }

    /** Returns {@link File} of cached image or <b>null</b> if image was not cached in disk cache */
    public static File findInCache(String imageUri, DiskCache diskCache) {
        File image = diskCache.get(imageUri);
        return image != null && image.exists() ? image : null;
    }

    /**
     * Removed cached image file from disk cache (if image was cached in disk cache before)
     *
     * @return <b>true</b> - if cached image file existed and was deleted; <b>false</b> - otherwise.
     */
    public static boolean removeFromCache(String imageUri, DiskCache diskCache) {
        File image = diskCache.get(imageUri);
        return image != null && image.exists() && image.delete();
    }

}

